package com.srwl.mytx.greendao;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import com.srwl.mytx.domain.InfiniteConnect;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "INFINITE_CONNECT".
*/
public class InfiniteConnectDao extends AbstractDao<InfiniteConnect, String> {

    public static final String TABLENAME = "INFINITE_CONNECT";

    /**
     * Properties of entity InfiniteConnect.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property IId = new Property(0, String.class, "iId", true, "I_ID");
        public final static Property CId = new Property(1, String.class, "cId", false, "C_ID");
        public final static Property ConnectKey = new Property(2, String.class, "connectKey", false, "CONNECT_KEY");
        public final static Property Layer = new Property(3, Integer.class, "layer", false, "LAYER");
        public final static Property Authority = new Property(4, String.class, "authority", false, "AUTHORITY");
    }

    private Query<InfiniteConnect> contact_InfiniteConnectsQuery;

    public InfiniteConnectDao(DaoConfig config) {
        super(config);
    }
    
    public InfiniteConnectDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"INFINITE_CONNECT\" (" + //
                "\"I_ID\" TEXT PRIMARY KEY NOT NULL ," + // 0: iId
                "\"C_ID\" TEXT," + // 1: cId
                "\"CONNECT_KEY\" TEXT," + // 2: connectKey
                "\"LAYER\" INTEGER," + // 3: layer
                "\"AUTHORITY\" TEXT);"); // 4: authority
        // Add Indexes
        db.execSQL("CREATE INDEX " + constraint + "IDX_INFINITE_CONNECT_C_ID ON \"INFINITE_CONNECT\"" +
                " (\"C_ID\" ASC);");
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"INFINITE_CONNECT\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, InfiniteConnect entity) {
        stmt.clearBindings();
 
        String iId = entity.getIId();
        if (iId != null) {
            stmt.bindString(1, iId);
        }
 
        String cId = entity.getCId();
        if (cId != null) {
            stmt.bindString(2, cId);
        }
 
        String connectKey = entity.getConnectKey();
        if (connectKey != null) {
            stmt.bindString(3, connectKey);
        }
 
        Integer layer = entity.getLayer();
        if (layer != null) {
            stmt.bindLong(4, layer);
        }
 
        String authority = entity.getAuthority();
        if (authority != null) {
            stmt.bindString(5, authority);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, InfiniteConnect entity) {
        stmt.clearBindings();
 
        String iId = entity.getIId();
        if (iId != null) {
            stmt.bindString(1, iId);
        }
 
        String cId = entity.getCId();
        if (cId != null) {
            stmt.bindString(2, cId);
        }
 
        String connectKey = entity.getConnectKey();
        if (connectKey != null) {
            stmt.bindString(3, connectKey);
        }
 
        Integer layer = entity.getLayer();
        if (layer != null) {
            stmt.bindLong(4, layer);
        }
 
        String authority = entity.getAuthority();
        if (authority != null) {
            stmt.bindString(5, authority);
        }
    }

    @Override
    public String readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0);
    }    

    @Override
    public InfiniteConnect readEntity(Cursor cursor, int offset) {
        InfiniteConnect entity = new InfiniteConnect( //
            cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // iId
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // cId
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // connectKey
            cursor.isNull(offset + 3) ? null : cursor.getInt(offset + 3), // layer
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4) // authority
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, InfiniteConnect entity, int offset) {
        entity.setIId(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));
        entity.setCId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setConnectKey(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setLayer(cursor.isNull(offset + 3) ? null : cursor.getInt(offset + 3));
        entity.setAuthority(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
     }
    
    @Override
    protected final String updateKeyAfterInsert(InfiniteConnect entity, long rowId) {
        return entity.getIId();
    }
    
    @Override
    public String getKey(InfiniteConnect entity) {
        if(entity != null) {
            return entity.getIId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(InfiniteConnect entity) {
        return entity.getIId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "infiniteConnects" to-many relationship of Contact. */
    public List<InfiniteConnect> _queryContact_InfiniteConnects(String cId) {
        synchronized (this) {
            if (contact_InfiniteConnectsQuery == null) {
                QueryBuilder<InfiniteConnect> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.CId.eq(null));
                contact_InfiniteConnectsQuery = queryBuilder.build();
            }
        }
        Query<InfiniteConnect> query = contact_InfiniteConnectsQuery.forCurrentThread();
        query.setParameter(0, cId);
        return query.list();
    }

}
